package edu.ccut.titan.component.impl.directory;

import java.util.Enumeration;

import org.osgi.framework.Bundle;

import edu.ccut.titan.component.ComponentFactory;
import edu.ccut.titan.component.IBundleInfo;
import edu.ccut.titan.component.TitanComponentException;

public class TitanLogicDirectoryInfo extends AbstractDirectoryInfo {

	private static final String TITAN_LOGIC_COMPONENT_FILE_POSTFIX = ".logic.xml";

	public TitanLogicDirectoryInfo() {

		super(TITAN_DIRECTORY_TYPE_LOGIC);
	}

	@SuppressWarnings("unchecked")
	public void load(Bundle bundle, IBundleInfo bundleInfo)
			throws TitanComponentException {
		Enumeration<String> logicFiles = bundle.getEntryPaths(super
				.getDirectoryPath());

		while (logicFiles.hasMoreElements()) {
			String logicFile = logicFiles.nextElement();

			if (logicFile != null
					&& logicFile.endsWith(TITAN_LOGIC_COMPONENT_FILE_POSTFIX)) {

				bundleInfo.addComponentInfo(ComponentFactory
						.getLogicComponentInfo(bundle, logicFile));
			}
		}
	}
}
